import ON_DEATH = require('death');

import ServerBase from "./startserver";
import startparam from './startparam';

import fs = require('fs');
import WebConstant from './common/WebConstant';

let server = new ServerBase(); 
//console.log(process.argv);
ON_DEATH(function(signal:any, err:any) {
    server.quit();
    process.exit(1);
});
/**
 * 启动方式 node server.js
 */
try{
    let pathArray = WebConstant.UPLOAD_PATH.split("/");
    let tryCreatePath = "";
    for(let i = 0; i < pathArray.length; i++){
        if(pathArray[i].length <= 0){
            continue;
        }
        tryCreatePath += pathArray[i]+"/";
        if(!fs.existsSync(tryCreatePath)){
            fs.mkdirSync(tryCreatePath);
        } 
    }
}
catch(ex){
    console.log("启动服务器出错，不能创建目录");

    process.exit(1);
}

server.start(startparam,0);
